<template>
	<view class="content">	
		<view class="login-box">
			<view class="item">
				 <input type="text" v-model="httpUrl" placeholder="接口地址"/>
			</view>
			<view class="item">
				 <input type="text" v-model="username" placeholder="请输入用户名"/>
			</view>
			<view class="item">
				 <input type="password" v-model="password" placeholder="请输入密码" />
			</view>
			<view class="item">
				<button type="default" @click="login">登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				httpUrl: 'http://192.168.1.61',
				username:'xiaoliang',
				password:'123456'
			}
		},
		onLoad() {

		},
		methods: {
			login(){
				let requestUrl=this.httpUrl+'/user/loginMobile';
				uni.request({
					method:'POST',
				    url: requestUrl,
				    data: {
				        username: this.username,
						password: this.password
				    },
				    header: {
				        'content-type': 'application/json' 
				    },
				    success: (res) => {
				        console.log(res.data);
						let resultData=res.data;
						let code=resultData.code;
						if(code==0){ //登录成功
							 let storageInfo={username:this.username,token:resultData.data.token,httpUrl:this.httpUrl};
							 uni.setStorage({
							     key: 'info',
							     data: JSON.stringify(storageInfo)
							 });
				
							 uni.navigateTo({
							     url: '../qrCode/qrCode'
							 });
							 
						}else{
							uni.showToast({
							    title: '登录失败',
							    duration: 2000
							});
						}
				    }
				});
			}
		}
	}
</script>

<style>
	.login-box{
		flex: 1;
		display: flex;
		flex-direction: column;
	}
	.login-box > .item{
		flex: 1;
	}
	.login-box > .item >input{
		height: 80rpx;
		border-bottom: solid 1px #eee;
		padding-left: 10rpx;
	}
	.login-box > .item >button{
		margin: 5rpx;
		margin-top: 10rpx;
	}
</style>
